﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

using WeChatDemo.Models.Photo;
using WeChatDemo.DataProvider.Photo;

namespace WeChatDemo.Controllers
{
    public class PhotoLikeController : ApiController
    {
        [HttpPost]
        public IHttpActionResult Post([FromBody]PhotoLike model)
        {
            if (DAOPhotoLike.Add(model))
            {
                return Created<PhotoLike>("success", model);
            }
            else
            {
                return InternalServerError();
            }
        }

        [HttpGet]
        public IHttpActionResult Get([FromUri] string where)
        {
            try
            {
                IEnumerable<PhotoLike> _list = null;
                _list = DAOPhotoLike.GetList(where);

                if (_list.Count<PhotoLike>() == 0)
                {
                    return Ok(new { count = 0 });
                }
                else
                {
                    return Ok(new { count = _list.Count<PhotoLike>(), results = _list });
                }
            }
            catch (Exception ex)
            {

                return InternalServerError(ex);
            }
        }
    }
}
